<?php

function smarty_function_url($params, &$smarty) {

    if (!is_array($params))
        return C("SITE_URL");

    if (in_array('mod_rewrite', apache_get_modules()))
        $url = '/';
    else
        $url=Q;

    if (!empty($params['module'])) {
        $url.=$params['module'] . '/';
        unset($params['module']);
    }
    if (!empty($params['class'])) {
        $url.=$params['class'] . '/';
        unset($params['class']);
    }
    if (!empty($params['function'])) {
        $url.=$params['function'] . '/';
        unset($params['function']);
    }
    if (!empty($params))
        $query = base64_encode(str_replace("&amp;", '&', http_build_query($params)));
    else
        $query='';

    if (substr_count($query, '=') >= 1)
        return $url . str_replace(array("==", '='), array(".html", ".htm"), $query);
    elseif (!empty($query))
        return $url . $query . '.shtml';
    else
        return $url;
}

?>
